home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 223_01 / fm.c < prev    next >
Text File  |  1980-01-01  |  1KB  |  55 lines

  1. /*    
  2. ** fm.c        File Modification Program    by F.A.Scacchitti  9/23/84
  3. **
  4. **        Written in Small-C  Version 2.7 or later
  5. **
  6. **    Copies from source file to new file modifying on the fly.
  7. **    Mod. description is in modify routine.
  8. **
  9. **    This program may be used as a shell for any ascii file
  10. **        modification utilities.
  11. */
  12.  
  13. #include <stdio.h>
  14.  
  15. FILE fdin, fdout;    /* file  i/o channel pointers */
  16. char c;            /* the byte we're modifying */
  17.  
  18. main(argc,argv) int argc; char *argv[]; {
  19.  
  20.    if (argc != 3) {
  21.       puts("\nfm usage: fm <source file> <new file> <CR>\n");
  22.       exit();
  23.    }
  24.    if((fdin = fopen(argv[1],"r")) == NULL) {
  25.       puts("\nUnable to open input file\n");
  26.       exit();
  27.    }
  28.    if((fdout = fopen(argv[2],"w")) == NULL) {
  29.       puts("\nUnable to create output file\n");
  30.       exit();
  31.    }
  32.  
  33.    while((c = fgetc(fdin)) != EOF)
  34. /*
  35. **    Here's where we modify the file
  36. */
  37.       fputc((modify(c)),fdout);
  38.  
  39.    fclose(fdin);
  40.    fclose(fdout);
  41.     
  42. }
  43.  
  44. /* this routine double spaces an ascii file or adds missing line feeds */
  45.  
  46. modify(c) char c; {
  47.  
  48.    if( c == CR) {
  49.       fputc(CR,fdout);
  50.       return(LF);
  51.    }else
  52.       return(c);
  53. }
  54.  
  55.